package com.SiLa.LispPlugin;

import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
import com.intellij.openapi.options.colors.AttributesDescriptor;
import com.intellij.openapi.options.colors.ColorDescriptor;
import com.intellij.openapi.options.colors.ColorSettingsPage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.Map;

public class LispColorSettingsPage implements ColorSettingsPage {

    private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[]{
            new AttributesDescriptor("Number", LispSyntaxHighlighter.NUMBER),
            new AttributesDescriptor("String", LispSyntaxHighlighter.STRING),
            new AttributesDescriptor("Comment", LispSyntaxHighlighter.COMMENT),
            new AttributesDescriptor("Keyword", LispSyntaxHighlighter.KEYWORD),
            new AttributesDescriptor("Symbol", LispSyntaxHighlighter.SYMBOL),
    };

    @Nullable
    @Override
    public Icon getIcon() {
        return LispIcons.FILE;
    }

    @NotNull
    @Override
    public SyntaxHighlighter getHighlighter() {
        return new LispSyntaxHighlighter();
    }

    @NotNull
    @Override
    public String getDemoText() {
        return "(defun sqrt-iter (guess x)\n" +
                "  (if (good-enough-p guess x)\n" +
                "      guess\n" +
                "      (sqrt-iter (improve guess x) x)))\n" +
                "\n" +
                "(defun improve (guess x)\n" +
                "  (mean (list guess (/ x guess))))\n" +
                "\n" +
                ";see format page 121-122\n" +
                "\n" +
                "(defun good-enough-p (guess x)\n" +
                "  (format t \"~% Guess =~7,4f     Guess^2 = ~7,4f    Error= ~7,4f\" guess \n" +
                "          (* guess guess) (abs (- (* guess guess) x)))\n" +
                "  (< (abs (- (* guess guess) x)) .001))";
    }

    @Nullable
    @Override
    public Map<String, TextAttributesKey> getAdditionalHighlightingTagToDescriptorMap() {
        return null;
    }

    @NotNull
    @Override
    public AttributesDescriptor[] getAttributeDescriptors() {
        return DESCRIPTORS;
    }

    @NotNull
    @Override
    public ColorDescriptor[] getColorDescriptors() {
        return ColorDescriptor.EMPTY_ARRAY;
    }

    @NotNull
    @Override
    public String getDisplayName() {
        return "Lisp";
    }
}
